package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 插入套餐数据
     * @param setmeal
     */
    @Insert("insert into setmeal (name, category_id, price, status, description, image, create_time, create_user, " +
            "update_time, update_user) VALUES (#{name}, #{categoryId}, #{price}, " +
            "#{status}, #{description}, #{image}, #{createTime}, #{createUser}, " +
            "#{updateTime}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    int insert(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<Setmeal> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    int delete(List<Long> ids);

    /**
     * 修改套餐状态
     * @param status
     * @param id
     */
    @Update("update setmeal set status = #{status} WHERE id = #{id}")
    int startOrStop(Integer status, Long id);

    /**
     * 修改套餐
     * @param setmeal
     * @return
     */
    @Update("update setmeal set name = #{name}, category_id = #{categoryId}, price = #{price}," +
            " status = #{status}, description = #{description}, image = #{image} WHERE id = #{id}" )
    int update(Setmeal setmeal);

    SetmealVO getById(Long id);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
